<template>
    <div class="learun-side" >
      <template v-for="(item,index) in list"  >
        <div style="padding:0 8px" v-if="item.type == 'divider'" :key="index">
           <el-divider></el-divider>
        </div>
       
        <div v-else @click="handleClick(index)" :class="['learun-side-item',{'selected':index == selected}]"  :key="index">
            <div class="learun-side-icon" >
              <i :class="item.icon"></i>
            </div>
            <span>{{$t(item.label)}}</span>
        </div>
      </template>
    </div>
</template>

<script>
export default {
    name:'l-side-list',
    props: {
        list:{
          type:Array,
          default:()=>[]
        }
    },
    data () {
        return {
          selected:0
        }
    },
    methods:{
      handleClick(index){
        if(this.selected != index){
          this.selected = index
          this.$emit('change',this.list[index])
        }
        this.$emit('click',this.list[index])
        
      }
    }
}
</script>
<style lang="scss" scoped>
/*侧边栏*/
.learun-side {
    &-item {
        position: relative;
        box-sizing: border-box;
        height: 40px;
        line-height: 40px;
        width: 100%;
        padding-left: 40px;
        font-size: 14px;
        cursor: pointer;
        color: #666;

        &.selected{
          background: rgba(24, 144, 255, 0.08);
          color: #409EFF;
        }

        &:hover{
          background: #f2f4f6;
        }

        
    }

    &-icon {
        position: absolute;
        height: 100%;
        width: 24px;
        top: 0;
        left: 16px;
    }

    .el-divider--horizontal{
      margin:8px 0!important;
    }
}
</style>